package com.study.leetcode;

import java.util.LinkedList;
import java.util.List;

public class Solution_77 {
    private static List<List<Integer>> combines = new LinkedList<>();

    public static List<List<Integer>> combine(int n, int k) {
        combines.clear();
        for (int i = n; i >= 1; i--) {
            List<Integer> integers = new LinkedList<>();
            integers.add(0, i);
            combine(integers, i, k - 1);
        }
        return combines;
    }

    public static void combine(List<Integer> integers, int n, int k) {
        if (n < k) {
            return;
        }
        if (k == 0) {
            combines.add(integers);
        } else {
            for (int i = n - 1; i >= 1; i--) {
                List<Integer> newIntegers = new LinkedList<>(integers);
                newIntegers.add(0, i);
                combine(newIntegers, i, k - 1);
            }
        }
    }

    public static void main(String[] args) {
        List<List<Integer>> combine = combine(3, 2);
        System.out.println("combine = " + combine);
    }
}
